<?php 
class Barang extends BaseController_Controller {	

	public function __construct()
	{
		parent::__construct();			
		$this->load->library('mdm/mstbarang');		 
	}

	public function index()
	{		
		$this->appendhtmlwithjs('',$data,'mdm/mstbrg.js',false);
	}

	public function delete()
	{		
		$id=json_decode($this->input->post('cb'),true);			
		if(count($id)>0)
		{
			$mdl=new MstBarang();
			$rslt['success']=$mdl->Delete($id);			
		}
		echo json_encode($rslt);
	}

	public function save()
	{			
		$mdl=new MstBarang( $this->input->post('KdBrg'));		
		$id=$mdl->KdBrg;	
		$mdl->KdBrg=$this->input->post('KdBrg');
		$mdl->NmBrg=$this->input->post('NmBrg');
		$mdl->BCode=$this->input->post('BCode');	
		$mdl->TypeBrg=$this->input->post('TypeBrg');
		$mdl->UnitId=$this->input->post('UnitId');
		$mdl->MinStock=$this->input->post('MinStock');	
		$mdl->InitStock=$this->input->post('InitStock');		
		$b=false;
		$rslt=array();

		if(!$id){			
			$b=$mdl->Create($id);	
		}
		else{			
		
			if($this->input->post('iscreate'))
			{ 
				$b=false;
				$rslt['message']='Data Already Exist';
				
			}
			else
			{			
				$b=$mdl->Update();	
			}		
		}
		
		$rslt['success']=$b;
		echo json_encode($rslt);	
	}	

	

	
  }
